package com.ruoyi.system.service.life;

import com.nlf.calendar.Lunar;
import com.ruoyi.system.domain.life.LifeFamilyFriends;
import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @author litongfei
 */
@Component("lunarTask")
public class LunarTask {


    @Resource
    private ILifeFamilyFriendsService iLifeFamilyFriendsService;

    public void lunarNoParams() {

        List<LifeFamilyFriends> lifeFamilyFriendsList = iLifeFamilyFriendsService.selectLifeFamilyFriendsList(new LifeFamilyFriends());
        if (CollectionUtils.isNotEmpty(lifeFamilyFriendsList)) {
            lifeFamilyFriendsList.forEach(lifeFamilyFriends1 -> {
                if (Objects.nonNull(lifeFamilyFriends1.getlBirthday())) {
                    LocalDate localDate = lifeFamilyFriends1.getlBirthday().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                    LocalDate nowDate = LocalDate.now();
                    LocalDate tomorrow = localDate.plusDays(-1L);
                    if (nowDate.getMonthValue() == tomorrow.getMonthValue() && nowDate.getDayOfMonth() == tomorrow.getDayOfMonth()) {
                        String sendMessage = "明天是" + lifeFamilyFriends1.getlRealName() + "的生日";
                        System.out.println(sendMessage);
                    }
                    if (nowDate.getMonthValue() == localDate.getMonthValue() && nowDate.getDayOfMonth() == localDate.getDayOfMonth()) {
                        String sendMessage = "今天是" + lifeFamilyFriends1.getlRealName() + "的生日";
                        System.out.println(sendMessage);
                    }


                }
            });
        }
        Lunar d = Lunar.fromDate(new Date());
        System.out.println(d);
        System.out.println(d.toFullString());

    }

    public static void main(String[] args) {
        LocalDate localDate = new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
        Lunar d = Lunar.fromYmd(localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth());
        System.out.println(d);
        System.out.println(d.toFullString());
    }
}
